package com.tuuzed.hydrogen.simple.model;

import android.os.Parcel;
import android.os.Parcelable;

import com.tuuzed.hydrogen.Model;
import com.tuuzed.hydrogen.annotation.Ignore;
import com.tuuzed.hydrogen.annotation.Unique;

import java.util.Date;

public class UserModel extends Model implements Parcelable {
    @Unique
    private String name;
    private String sex;
    private int age;
    private String password;
    private Date createDate;
    @Ignore
    private String ignore;

    public UserModel() {
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getSex() {
        return sex;
    }

    public void setSex(String sex) {
        this.sex = sex;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public Date getCreateDate() {
        return createDate;
    }

    public void setCreateDate(Date createDate) {
        this.createDate = createDate;
    }

    public String getIgnore() {
        return ignore;
    }

    public void setIgnore(String ignore) {
        this.ignore = ignore;
    }

    @Override
    public String toString() {
        return "UserModel{" +
                "name='" + name + '\'' +
                ", sex='" + sex + '\'' +
                ", age=" + age +
                ", password='" + password + '\'' +
                ", createDate=" + createDate +
                ", ignore='" + ignore + '\'' +
                "} " + super.toString();
    }


    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeString(this.name);
        dest.writeString(this.sex);
        dest.writeInt(this.age);
        dest.writeString(this.password);
        dest.writeLong(this.createDate != null ? this.createDate.getTime() : -1);
        dest.writeString(this.ignore);
    }

    protected UserModel(Parcel in) {
        this.name = in.readString();
        this.sex = in.readString();
        this.age = in.readInt();
        this.password = in.readString();
        long tmpCreateDate = in.readLong();
        this.createDate = tmpCreateDate == -1 ? null : new Date(tmpCreateDate);
        this.ignore = in.readString();
    }

    public static final Creator<UserModel> CREATOR = new Creator<UserModel>() {
        @Override
        public UserModel createFromParcel(Parcel source) {
            return new UserModel(source);
        }

        @Override
        public UserModel[] newArray(int size) {
            return new UserModel[size];
        }
    };
}
